#coding:utf-8

from django import template

register = template.Library()


@register.filter(name='substring')
def substring(value, length):
    if not value:
        return u'无摘要'

    if len(value) > length:
        return '%s...' % value[:length]
    return value[:length]


@register.filter(name='sub')
def sub(value, param):
    if not value:
        return value
    try:
        value = int(value)
        param = int(param)
    except TypeError:
        return value
    return value - param

@register.filter(name='chgModName')
def chgModName(value):
    _temp_str=""
    if value=="shframeworkseed":
        _temp_str="搜狐新闻客户端"
    elif value=="newssdk":
        _temp_str="轻量客户端"
    return _temp_str

@register.filter(name='dottedVer')
def dottedVer(value):
    _temp_str=str(value)
    if len(_temp_str)==3:
        _temp_str=_temp_str+"0"
    newStr=_temp_str[0:-1]+"."+_temp_str[-1:]
    return newStr

@register.filter(name='typeName')
def typeName(value):
    _temp_str=""
    if value=="dev":
        _temp_str="开发"
    elif value=="min":
        _temp_str="压缩"
    elif value=="ent":
        _temp_str="加密"
    return _temp_str